package com.googlecode.garbagecan.test.socket.sample7;

import org.apache.commons.pool.PoolableObjectFactory;

public class MyClientPoolableObjectFactory implements PoolableObjectFactory {

	private String host;
	private int port;
	private boolean enableSSL;

	public MyClientPoolableObjectFactory(String host, int port, boolean enableSSL) {
		this.host = host;
		this.port = port;
		this.enableSSL = enableSSL;
	}

	@Override
	public Object makeObject() throws Exception {
		MyClient myClient = new MyClient(host, port, enableSSL);
		myClient.connect();
		return myClient;
	}

	@Override
	public void destroyObject(Object o) throws Exception {
		MyClient myClient = (MyClient) o;
		myClient.close();
	}

	@Override
	public boolean validateObject(Object o) {
		MyClient myClient = (MyClient) o;
		return myClient.ping();
	}

	@Override
	public void activateObject(Object o) throws Exception {
		// do nothing
	}

	@Override
	public void passivateObject(Object o) throws Exception {
		// do nothing
	}
}
